<template>
  <div class="boxContent">
    <div class="appBox">
      <div class="mb20 f16 fb primary"
           v-if="$route.query.name ">{{ $route.query.name }}</div>
      <div class="searchList">
        <el-form :model="state.params"
                 ref="FormInstance "
                 class="boxFrom">
          <div class="searchBox">
            <template v-for="(item, index) in state.totalInputColumns"
                      :key="index">
              <el-form-item v-if="item.type == 'input'">
                <el-input v-model="state.params[item.key]"
                          :placeholder="item.label"
                          clearable></el-input>
              </el-form-item>
              <el-form-item v-if="item.type == 'time'">
                <el-date-picker v-model="state.params[item.key]"
                                type="date"
                                :placeholder="item.label" />
              </el-form-item>
              <el-form-item v-if="item.type == 'select'">
                <el-select v-model="state.params[item.key]"
                           :placeholder="item.label"
                           clearable
                           v-if="item.key == 'companyId'">
                  <el-option />
                </el-select>

                <el-cascader v-model="state.params[item.key]"
                             :options="state.propsCity"
                             :props="state.props"
                             :placeholder="item.label"
                             clearable
                             v-if="item.key == 'city'" />

                <el-select v-model="state.params[item.key]"
                           :placeholder="item.label"
                           clearable
                           v-if="item.key == 'workTypeId'">
                  <el-option label="长白班"
                             value="长白班" />
                  <el-option label="两班倒"
                             value="两班倒" />
                </el-select>
                <el-select v-model="state.params[item.key]"
                           :placeholder="item.label"
                           clearable
                           v-if="item.key == 'typeId'">
                  <el-option :label="i.dictValue"
                             :value="i.id"
                             v-for="i in state.totalInputColumnsOption.positionType"
                             :key="i" />
                </el-select>
                <el-select style="width: 130px"
                           v-model="state.params[item.key]"
                           :placeholder="item.label"
                           clearable
                           v-if="item.key == 'startYear'">
                  <el-option v-for="i in state.totalInputColumnsOption.startYearList"
                             :key="i"
                             :label="i.label"
                             :value="i.value" />
                </el-select>
                <div v-if="item.yaer == 'year'">&nbsp; -</div>
                <el-select style="width: 130px"
                           v-model="state.params[item.key]"
                           :placeholder="item.label"
                           clearable
                           v-if="item.key == 'endYear'">
                  <el-option v-for="i in state.totalInputColumnsOption.endYearList"
                             :key="i"
                             :disabled="state.params.startYear > i.value"
                             :label="i.label"
                             :value="i.value" />
                </el-select>
              </el-form-item>
            </template>
          </div>

          <el-form-item class="btns">
            <el-button v-preventReClick
                       type="primary"
                       @click="methods.handleAction('add')"
                       v-if="$route.query.id"
                       v-permission="1075">新增</el-button>
            <el-button v-preventReClick
                       type="primary"
                       plain
                       @click="methods.handleAction('query')">搜索</el-button>
            <el-button v-preventReClick
                       @click="methods.handleAction('reset')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="tabaleBox">
        <el-table border
                  :data="state.tableData"
                  style="width: 100%"
                  :header-cell-style="{ color: '#000' }"
                  v-loading="state.loading">
          <el-table-column prop="companyname"
                           label="父企业名称"
                           show-overflow-tooltip
                           align="left" />
          <el-table-column prop="childcompanyname"
                           label="子企业名称"
                           show-overflow-tooltip
                           align="left" />
          <el-table-column prop="createtime"
                           label="创建时间"
                           show-overflow-tooltip
                           align="center"
                           width="180" />
          <el-table-column prop="employeenumber"
                           label="招聘数量"
                           show-overflow-tooltip
                           align="center"
                           width="160" />
          <el-table-column prop="inductionnumber"
                           label="企业就职人数"
                           show-overflow-tooltip
                           align="center"
                           width="160" />
          <el-table-column prop="inductednumber"
                           label="已招聘人数"
                           show-overflow-tooltip
                           align="center"
                           width="160" />
          <el-table-column prop="recruitingnumber"
                           label="正在招聘岗位"
                           show-overflow-tooltip
                           width="160"
                           align="center" />
          <el-table-column prop="yesterdaysignnumber"
                           label="昨日打卡人数"
                           show-overflow-tooltip
                           width="160"
                           align="center" />
          <el-table-column prop="btns"
                           label="操作"
                           show-overflow-tooltip
                           align="center"
                           width="100"
                           fixed="right">
            <template #default="scope">
              <div class=" btnsDatil">
                <div @click="methods.handleAction('edit', scope.row)"
                     v-permission="1074">编辑</div>
                <!-- <div @click="methods.handleAction('delete', scope.row)">删除</div> -->
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination">
        <el-pagination background
                       v-model:current-page="state.params.pageNum"
                       v-model:page-size="state.params.pageSize"
                       :page-sizes="[10, 20, 30, 50]"
                       layout="total, sizes, prev, pager, next, jumper"
                       :total="state.totalSize"
                       @size-change="methods.handleSizeChange"
                       @current-change="methods.handleCurrentChange" />
      </div>

    </div>
  </div>
</template>
  
  <script setup>
import {
  onMounted,
  reactive,
  getCurrentInstance,
} from "vue";
import { ElMessage, ElLoading, ElMessageBox } from "element-plus";
import { useRouter } from "vue-router";
const router = useRouter();
const app = getCurrentInstance()?.proxy;
const initState = () => {
  return {
    loading: false,
    propsCity: [],
    dialogImg: false,
    dialogImgData: null,
    previewImgData: [],
    dialogDescribeData: null,
    dialogDescribe: false,
    totalSize: 0,
    tableData: [],
    params: {
      pageNum: 1,
      pageSize: 10,
      cid: app.$route.query.id

    },
    totalInputColumns: [
      { key: "ccname", label: "子企业名称", type: "input" },

    ],
  };
};
const userInfor = JSON.parse(localStorage.getItem('userInfor'))
console.log(userInfor);
const state = reactive(initState());
onMounted(() => {

  methods.getDataList();
});
const methods = {
  handleAction (type, data) {
    switch (type) {
      case "add": //新增
        router.push("/enterprise/son/add?cid=" + app.$route.query.id);
        break;
      case "query": //查询
        methods.getDataList();
        break;
      case "reset": // 重置
        state.params = initState().params;
        break;
      case "edit": // 编辑
        router.push("/enterprise/son/add?id=" + data.id + '&cid=' + data.cid);
        break;
      case "delete": // 删除
        ElMessageBox.confirm("请确认是否删除该子企业?", "删除子企业", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            app.$http.get("/childCompany/deleteById?id=" + data.id).then((res) => {
              if (res.code == 200) {
                methods.getDataList();
                ElMessage({
                  type: "success",
                  message: "已删除",
                });
              }
            });
          })
          .catch(() => {
            methods.getDataList();
            ElMessage({
              type: "info",
              message: "已取消",
            });
          });

        break;
    }
  },

  getDataList () {
    state.loading = true
    app.$get("/company/manager/childcompany", state.params).then((res) => {
      state.tableData = res.data.data;
      state.totalSize = res.data.total;
      state.loading = false
    }).catch(() => {
      state.loading = false
    })
  },
  //分页变化
  handleSizeChange () {
    state.params.pageNum = 1;
    methods.getDataList();
  },
  //表格翻页
  handleCurrentChange () {
    methods.getDataList();
  },
};
  </script>
  
  <style lang="scss" scoped>
.appBox {
  background: #fff;
  border-radius: 5px;
  padding: 20px;
  height: calc(100% - 20px);
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  .tabaleBox {
    overflow: hidden;
    flex: 1;
  }
  .btnsDatil {
    color: #0079fe;
    cursor: pointer;
  }
  .pagination {
    margin-top: 20px;
    height: 50px;
    display: flex;
    justify-content: flex-end;
  }
  ::v-deep(.el-dialog__body) {
    max-height: 380px;
  }
  .imgs {
    flex-wrap: wrap;
    .forbox {
      // width: 150px;
      height: 150px;
      margin: 10px 0 0 10px;
    }
    .imgBox {
      height: 100%;
      width: auto;
    }
    .videoBox {
      width: auto;
      height: 100%;
    }
  }

  // .imgs .forbox:nth-child(4n + 1) {
  //   margin-left: 0;
  // }
}
</style>
  